package chpt07;

import java.util.Arrays;
import java.util.Scanner;

//可以对RuntimeException异常进行处理也可以不进行处理
public class RuntimeExceptionTest {
	
	
/*	public static void main(String[] args) {
		int[] x = new int[3];
		Scanner inputScan = new Scanner(System.in);
		for(int i = 0; i < x.length;){
			System.out.println("Please input the "+i+" integer:");
			String inputInt = inputScan.nextLine();  
			x[i] = Integer.parseInt(inputInt);  //注意这里！
			i++;
		}
		System.out.println(Arrays.toString(x));
	}*/
	
	public static void main(String[] args) {
		int[] x = new int[3];
		Scanner inputScan = new Scanner(System.in);
		for(int i = 0; i < x.length;){
			System.out.println("Please input the "+i+" integer:");
			String inputInt = inputScan.nextLine();  
			
			try {
				x[i] = Integer.parseInt(inputInt);  //注意这里！
				i++;
				System.out.println("i="+i);
			} catch (NumberFormatException e) {
				e.printStackTrace();
				System.out.println("输入的字符串:"+inputInt+"不能被转换成int");
			}finally{
				System.out.println("finally block中的代码无论是否发生异常总是会被执行");
			}
			
		}
		System.out.println(Arrays.toString(x));
	}

}
